<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>My JSP 'bookdesc.jsp' starting page</title>
	<meta http-equiv="content-type" content="text/html;charset=utf-8">
<link rel="stylesheet" type="text/css" href="<c:url value='/adminjsps/admin/css/book/add.css'/>">
<link rel="stylesheet" type="text/css" href="<c:url value='/jquery/jquery.datepick.css'/>">
<script type="text/javascript" src="<c:url value='/jquery/jquery-2.1.1.js'/>"></script>
<script type="text/javascript" src="<c:url value='/jquery/jquery.datepick.js'/>"></script>
<script type="text/javascript" src="<c:url value='/jquery/jquery.datepick-zh-CN.js'/>"></script>
<script type="text/javascript">
$(function () {
	$("#publishtime").datepick({dateFormat:"yy-mm-dd"});
	$("#factoryTime").datepick({dateFormat:"yy-mm-dd"});
	
	$("#btn").addClass("btn1");
	$("#btn").hover(
		function() {
			$("#btn").removeClass("btn1");
			$("#btn").addClass("btn2");
		},
		function() {
			$("#btn").removeClass("btn2");
			$("#btn").addClass("btn1");
		}
	);
	
	$("#btn").click(function() {
	    var car={};
	    var brand = $("#brand").val();
		var bname = $("#bname").val();
		var currPrice = $("#currPrice").val();
		var price = $("#price").val();
		var discount = $("#discount").val();
		var image_w = $("#image_w").val();
		var image_b = $("#image_b").val();
		
		if(!brand||!bname || !currPrice || !price || !discount || !image_w || !image_b) {
			alert("品牌、名称、当前价、定价、折扣、大图、小图都不能为空！");
			return false;
		}
		
		if(isNaN(currPrice) || isNaN(price) || isNaN(discount)) {
			alert("当前价、定价、折扣必须是小数或整数！");
			return false;
		}
		
	   /*  car.brand = $("#brand").val();
		car.bname = $("#bname").val();
		car.currPrice = $("#currPrice").val();
		car.price = $("#price").val();
		car.discount = $("#discount").val();
		car.image_w = $("#image_w").val();
		car.image_b = $("#image_b").val();
		
		
		car.manufacturer = $("#manufacturer").val();
		car.supplier = $("#supplier").val();
		car.energyType = $("#energyType").val();
		car.publishTime = $("#publishTime").val();
		car.level = $("#level").val();
		car.structure = $("#structure").val();
		car.factoryTime = $("#factoryTime").val();
		car.engineModel = $("#engineModel").val();
		car.tyreBrand = $("#tyreBrand").val();
		car.image_b = $("#image_b").val();
		var json=JSON.stringify(car);
	    $.ajax({
		type:"POST",
		url:"/carSalesSystem/admin/car/addCar.do",
		data:json,
		dataType:"JSON",
		async:true,
		cache:false,
		success:function(arr){
			prompt("保存数据成功");
		}
	  }); */

		$("#form").submit();
	});
});

function loadChildren(){
	var pid = $("#pid").val();
	$.ajax({
		type:"POST",
		url:"/carSalesSystem/admin/book/ajaxFindChildren.do",
		data:{pid:pid},
		dataType:"JSON",
		async:true,
		cache:false,
		success:function(arr){
			$("#cid").empty();//删除元素的子元素
			$("#cid").append($("<option>===请选择2级分类===</option>"));//4.添加头
			// 5. 循环遍历数组，把每个对象转换成<option>添加到cid中
			for(var i = 0; i < arr.length; i++) {
				var option = $("<option>").val(arr[i].cid).text(arr[i].cname);
				$("#cid").append(option);
			}
		}
	});
}

</script>
<style>
          label { float: left; width: 10em; margin-right: 1em; text-align: right; }
        .p{
            color:red;
            margin-left:20px;
            display:inline-block;
        }
      .buttton {
	border: 0;
	width: 142px;
	height: 33px;
	margin-top: 10px;
	font-size: 18px;
	font-weight: 900;
	text-align: left;
	padding-top: 1px;
	padding-left: 32px;
	color: #fff;
   }
    </style>
  </head>
  <body>
  <div>
   <p style="font-weight: 900; color: red;">${msg }</p>
   <form action="/carSalesSystem/admin/car/addCar.do" enctype="multipart/form-data" method="post" id="form">
    <div>
	    <ul>
	    	<li>
            <label for="brand" ><span class="p">*</span>品牌:</label>
	    	<!-- <input id="brand"   type="text" name="brand" value="" style="width:240px;"/> -->
	    	<select name="brand" id="brand"   style="width:240px;" >   
                                    <option value="奔驰">奔驰</option>   
                                    <option value="宝马">宝马</option> 
                                    <option value="大众">大众</option>   
                                    <option value="劳斯莱斯">劳斯莱斯</option>  
                                    <option value="奥迪">奥迪</option>   
                                    <option value="丰田">丰田</option>  
                                    <option value="本田">本田</option>   
                                    <option value="现代">现代</option>  
                                    <option value="起亚">起亚</option>   
                                    <option value="别克">别克</option>  
                                    <option value="长城">长城</option>   
                                    <option value="马自达">马自达</option>  
                                    <option value="日产">日产</option>   
                                    <option value="路虎">路虎</option>    
             </select> 
	    	</li>
	    	<li>
            <label for="bname" ><span class="p">*</span>名称:</label>
	    	<input id="bname"   type="text" name="bname" value="" style="width:240px;"/>
	    	</li>
	    	<li> 
            <label for="currPrice" ><span class="p">*</span>当前价:</label>
            <input id="currPrice" type="text" name="currPrice" value="" style="width:240px;"/>
	    	</li>
	    	<li>
            <label for="price" ><span class="p">*</span>定价:</label>
            <input id="price"   type="text" name="price" value="" style="width:240px;"/>
	    	</li>
	    	<li>
            <label for="discount" ><span class="p">*</span>折扣:</label>
            <input id="discount"   type="text" name="discount" value="" style="width:240px;"/>
	    	</li>
	    	<li>
            <label>制造商:</label>
            <input id="manufacturer" type="text" name="manufacturer" value="" style="width:240px;"/>
	    	</li>
	    	<li>
            <label for="supplier" >供货商:</label>
	    	<input id="supplier"   type="text" name="supplier" value="" style="width:240px;"/>
	    	</li>
	    	<li>
            <label for="factoryTime" >出厂时间:</label>
	    	<input id="factoryTime"   type="datetime" name="factoryTime" value="" style="width:240px;"/>
	    	</li>
	    	<li>
            <label for="publishtime" >上市时间:</label>
	    	<input id="publishtime"   type="datetime" name="publishtime" value="" style="width:240px;"/>
	    	</li>
	    	<li>
            <label for="engineModel" >发动机型号:</label>
	    	<input id="engineModel"   type="text" name="engineModel" value="" style="width:240px;"/>
	    	</li>
	    	<li>
            <label for="tyreBrand" >轮胎品牌:</label>
	    	<input id="tyreBrand"   type="text" name="tyreBrand" value="" style="width:240px;"/>
	    	</li>
	    	<li>
            <label for="image_w" ><span class="p">*</span>大图:</label>
            <input id="image_w"   type="file" name="fileItem" style="width:240px;"/>
	    	</li>
	    	<li>
            <label for="image_b" ><span class="p">*</span>小图:</label>
            <input id="image_b"   type="file" name="fileItem"/>
            </li>
	    </ul>
			<tr>
			    <td>
					<input type="button" id="btn" class="buttton" value="添加新车信息"/>
				</td>
			</tr>
		</table>
	</div>
   </form>
  </div>

  </body>
</html>
